<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body>
    <div class="vue">
        <div class="index-total aui-row">
            <div class="aui-col-xs-6">
                <div class="title">今日营收(元)</div>
                <div class="value">{{today.money}}</div>
            </div>
            <div class="aui-col-xs-6">
                <div class="title">今日笔数(笔)</div>
                <div class="value">{{today.amount}}</div>
            </div>
        </div>
        <div class="index-action">
            <div class="qrcode" @click="qrcodePage">
                <img src="../image/icon02.png">
                <span class="link">二维码</span>
            </div>
            <div class="bill" @click="billPage">
                <img src="../image/icon03.png">
                <span class="link">账单</span>
            </div>
            <div class="member" @click="memberPage">
                <img src="../image/icon04.png">
                <span class="link">会员</span>
            </div>
            <div class="message" @click="messagePage">
                <img src="../image/icon05.png">
                <span class="link">消息</span>
                <div class="new-message-count" v-if="newMessageCount>0">{{newMessageCount}}</div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/base64.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script type="text/javascript">
        apiready = function() {

            // api.alert({
            //     title: '提示',
            //     msg: '测试版V0.02',
            // }, function(ret, err) {
            //
            // });

            var user = app.getUser()
                // console.log(user.business_id)

            api.setRefreshHeaderInfo({
                loadingImg: 'widget://image/refresh.png',
                bgColor: '#fe6060',
                textColor: '#ffffff',
                textDown: '下拉刷新...',
                textUp: '松开刷新...'
            }, function(ret, err) {
                Ve.getInfo(function() {
                    api.refreshHeaderLoadDone();
                })
            });

            var Ve = new Vue({
                el: '.vue',
                data: {
                    today: {
                        money: '0.00',
                        amount: '0'
                    },
                    newMessageCount: 0
                },
                methods: {
                    getInfo: function(callback) {
                        app.request.post('/myhome/business_info', {
                            business_id: user.business_id,
                            signature: app.sign(user.business_id)
                        }, {}, function(res) {
                            // console.log(JSON.stringify(res))
                            callback && callback()
                            if (res.code == 1) {
                                Ve.today.money = res.total_money;
                                Ve.today.amount = res.money_count;
                            } else {
                                app.error(res.msg);
                            }
                        })
                    },
                    getMessageTag: function() {
                        app.request.post('/myhome/getMsgCount', {
                            business_id: user.business_id,
                            signature: app.sign(user.business_id)
                        }, {}, function(res) {
                            if (res.code == 1) {
                                Ve.newMessageCount = res.count
                            } else {
                                app.error(res.msg)
                            }
                        })
                    },
                    qrcodePage: function() {
                        api.openWin({
                            name: 'qrcode',
                            url: 'qrcode.html'
                        });
                    },
                    billPage: function() {
                        api.openWin({
                            name: 'bill',
                            url: 'bill.html'
                        });
                    },
                    memberPage: function() {
                        api.openWin({
                            name: 'member',
                            url: 'member.html'
                        });
                    },
                    messagePage: function() {
                        api.openWin({
                            name: 'message',
                            url: 'message.html'
                        });
                    }
                },
                created: function() {
                    this.getInfo(),
                        this.getMessageTag()
                }
            })
        }
    </script>
</body>

</html>
